from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-24 14:04:07.906292
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 24, Dec, 2021
Time: 14:04:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6109
Nobs: 515.000 HQIC: -48.0619
Log likelihood: 5964.02 FPE: 1.00171e-21
AIC: -48.3526 Det(Omega_mle): 8.42507e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357823 0.077737 4.603 0.000
L1.Burgenland 0.099903 0.043583 2.292 0.022
L1.Kärnten -0.115503 0.022494 -5.135 0.000
L1.Niederösterreich 0.178286 0.090521 1.970 0.049
L1.Oberösterreich 0.119092 0.090939 1.310 0.190
L1.Salzburg 0.282769 0.046965 6.021 0.000
L1.Steiermark 0.022705 0.060574 0.375 0.708
L1.Tirol 0.109418 0.048883 2.238 0.025
L1.Vorarlberg -0.081176 0.043167 -1.880 0.060
L1.Wien 0.032704 0.082396 0.397 0.691
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.017102 0.171537 0.100 0.921
L1.Burgenland -0.047946 0.096171 -0.499 0.618
L1.Kärnten 0.035393 0.049636 0.713 0.476
L1.Niederösterreich -0.207786 0.199746 -1.040 0.298
L1.Oberösterreich 0.452336 0.200668 2.254 0.024
L1.Salzburg 0.314267 0.103634 3.032 0.002
L1.Steiermark 0.108389 0.133664 0.811 0.417
L1.Tirol 0.316221 0.107866 2.932 0.003
L1.Vorarlberg 0.010757 0.095253 0.113 0.910
L1.Wien 0.011398 0.181816 0.063 0.950
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218315 0.039624 5.510 0.000
L1.Burgenland 0.092387 0.022215 4.159 0.000
L1.Kärnten -0.005226 0.011466 -0.456 0.649
L1.Niederösterreich 0.226105 0.046140 4.900 0.000
L1.Oberösterreich 0.164365 0.046353 3.546 0.000
L1.Salzburg 0.037736 0.023939 1.576 0.115
L1.Steiermark 0.029868 0.030876 0.967 0.333
L1.Tirol 0.078010 0.024916 3.131 0.002
L1.Vorarlberg 0.055549 0.022003 2.525 0.012
L1.Wien 0.103951 0.041998 2.475 0.013
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153539 0.039169 3.920 0.000
L1.Burgenland 0.043154 0.021960 1.965 0.049
L1.Kärnten -0.013149 0.011334 -1.160 0.246
L1.Niederösterreich 0.157518 0.045610 3.454 0.001
L1.Oberösterreich 0.343879 0.045821 7.505 0.000
L1.Salzburg 0.099732 0.023664 4.215 0.000
L1.Steiermark 0.111894 0.030521 3.666 0.000
L1.Tirol 0.089574 0.024630 3.637 0.000
L1.Vorarlberg 0.054624 0.021750 2.511 0.012
L1.Wien -0.041822 0.041516 -1.007 0.314
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150133 0.074157 2.025 0.043
L1.Burgenland -0.034673 0.041576 -0.834 0.404
L1.Kärnten -0.036535 0.021458 -1.703 0.089
L1.Niederösterreich 0.131330 0.086352 1.521 0.128
L1.Oberösterreich 0.176290 0.086751 2.032 0.042
L1.Salzburg 0.256628 0.044802 5.728 0.000
L1.Steiermark 0.080944 0.057784 1.401 0.161
L1.Tirol 0.134141 0.046631 2.877 0.004
L1.Vorarlberg 0.104790 0.041179 2.545 0.011
L1.Wien 0.039609 0.078601 0.504 0.614
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078373 0.058703 1.335 0.182
L1.Burgenland 0.016401 0.032912 0.498 0.618
L1.Kärnten 0.050820 0.016987 2.992 0.003
L1.Niederösterreich 0.181906 0.068357 2.661 0.008
L1.Oberösterreich 0.330766 0.068673 4.817 0.000
L1.Salzburg 0.050887 0.035466 1.435 0.151
L1.Steiermark -0.004192 0.045743 -0.092 0.927
L1.Tirol 0.127203 0.036914 3.446 0.001
L1.Vorarlberg 0.059503 0.032598 1.825 0.068
L1.Wien 0.109694 0.062221 1.763 0.078
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174975 0.071048 2.463 0.014
L1.Burgenland 0.010370 0.039833 0.260 0.795
L1.Kärnten -0.061081 0.020559 -2.971 0.003
L1.Niederösterreich -0.111122 0.082732 -1.343 0.179
L1.Oberösterreich 0.230785 0.083114 2.777 0.005
L1.Salzburg 0.039544 0.042924 0.921 0.357
L1.Steiermark 0.262035 0.055362 4.733 0.000
L1.Tirol 0.489746 0.044676 10.962 0.000
L1.Vorarlberg 0.070183 0.039453 1.779 0.075
L1.Wien -0.102399 0.075306 -1.360 0.174
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138970 0.078710 1.766 0.077
L1.Burgenland -0.011078 0.044128 -0.251 0.802
L1.Kärnten 0.063014 0.022776 2.767 0.006
L1.Niederösterreich 0.175315 0.091654 1.913 0.056
L1.Oberösterreich -0.081756 0.092077 -0.888 0.375
L1.Salzburg 0.223668 0.047553 4.704 0.000
L1.Steiermark 0.138475 0.061332 2.258 0.024
L1.Tirol 0.054347 0.049494 1.098 0.272
L1.Vorarlberg 0.140692 0.043707 3.219 0.001
L1.Wien 0.161762 0.083427 1.939 0.053
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.463295 0.043830 10.570 0.000
L1.Burgenland 0.000699 0.024573 0.028 0.977
L1.Kärnten -0.014307 0.012683 -1.128 0.259
L1.Niederösterreich 0.181070 0.051037 3.548 0.000
L1.Oberösterreich 0.249899 0.051273 4.874 0.000
L1.Salzburg 0.020011 0.026480 0.756 0.450
L1.Steiermark -0.007756 0.034153 -0.227 0.820
L1.Tirol 0.074732 0.027561 2.712 0.007
L1.Vorarlberg 0.056547 0.024338 2.323 0.020
L1.Wien -0.022483 0.046456 -0.484 0.628
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029986 0.092244 0.152773 0.142356 0.069837 0.081234 0.013665 0.209470
Kärnten 0.029986 1.000000 -0.031283 0.134409 0.051911 0.076101 0.454546 -0.078460 0.102145
Niederösterreich 0.092244 -0.031283 1.000000 0.290029 0.105557 0.257341 0.048870 0.148226 0.253603
Oberösterreich 0.152773 0.134409 0.290029 1.000000 0.199250 0.288167 0.153985 0.133385 0.194856
Salzburg 0.142356 0.051911 0.105557 0.199250 1.000000 0.123975 0.059275 0.112015 0.072652
Steiermark 0.069837 0.076101 0.257341 0.288167 0.123975 1.000000 0.131589 0.091418 0.012614
Tirol 0.081234 0.454546 0.048870 0.153985 0.059275 0.131589 1.000000 0.063128 0.125369
Vorarlberg 0.013665 -0.078460 0.148226 0.133385 0.112015 0.091418 0.063128 1.000000 -0.005665
Wien 0.209470 0.102145 0.253603 0.194856 0.072652 0.012614 0.125369 -0.005665 1.000000